from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options
from service import service

# url=r"http://192.168.4.6/upload/"
# dr=webdriver.Chrome(options=options,service=service)
# dr.get(url)
# dr.maximize_window()
# sleep(2)
# ----------------------------------
# 打开论坛
url=r"http://192.168.4.6/upload"
dr=webdriver.Chrome(options=options,service=service)
dr.get(url)
dr.maximize_window()
sleep(3)
# 立即注册
dr.find_element(By.CSS_SELECTOR,'#lsform > div > div > table > tbody > tr:nth-child(2) > td:nth-child(4) > a').click()
sleep(3)
# 用户名输入
dr.find_element(By.ID,'Muc6WG').clear()
dr.find_element(By.ID,'Muc6WG').send_keys('lsls')
sleep(3)
# 密码输入
dr.find_element(By.ID,'WLYVuY').clear()
dr.find_element(By.ID,'WLYVuY').send_keys('123456')
sleep(3)
# 确认密码输入
dr.find_element(By.ID,'eakvBJ').clear()
dr.find_element(By.ID,'eakvBJ').send_keys('123456')
sleep(3)
# Email输入
dr.find_element(By.ID,'BQIr0s').clear()
dr.find_element(By.ID,'BQIr0s').send_keys('ls@qq.com')
sleep(3)
# 提交
dr.find_element(By.ID,'registerformsubmit').click()
sleep(3)

# ------------------------------------------------
# 登录
dr.find_element(By.ID,'ls_username').clear()
dr.find_element(By.ID,'ls_username').send_keys('admin')
sleep(3)
dr.find_element(By.ID,'ls_password').clear()
dr.find_element(By.ID,'ls_password').send_keys('root')
sleep(3)
dr.find_element(By.XPATH,'//*[@id="lsform"]/div/div/table/tbody/tr[2]/td[3]/button/em').click()
sleep(3)

# 发帖子
    # 默认版块
dr.find_element(By.XPATH,'//*[@id="category_1"]/table/tbody/tr[1]/td[2]/h2/a').click()
sleep(3)
    # 发帖子
dr.find_element(By.XPATH,'//*[@id="newspecial"]/img').click()
sleep(3)
    # 文本框标题内容
dr.find_element(By.ID,'subject').clear()
dr.find_element(By.ID,'subject').send_keys('第一个帖子')
sleep(3)
# 输入发帖的内容
    # 1、定位iframe框架
i=dr.find_element(By.XPATH,'//*[@id="e_iframe"]')
dr.switch_to.frame(i)
    # 2、输入发帖内容
dr.find_element(By.XPATH,'/html/body').clear()
dr.find_element(By.XPATH,'/html/body').send_keys('第一个帖子a')
sleep(3)
    # 3、跳出iframe框架
dr.switch_to.parent_frame()
sleep(3)
# 发表帖子
dr.find_element(By.ID,'postsubmit').click()
sleep(3)

# 查看帖子
    #点击返回列表
dr.find_element(By.XPATH,'//*[@id="pgt"]/span/a').click()
sleep(3)
    # 1、点击默认版块
# dr.find_element(By.XPATH,'//*[@id="category_1"]/table/tbody/tr[1]/td[2]/h2/a').click()
# sleep(2)
    # 2、点击帖子
dr.find_element(By.CLASS_NAME,'s.xst').click()
sleep(3)
    # 3、回复帖子
    # 输入回复内容
dr.find_element(By.ID,'fastpostmessage').clear()
dr.find_element(By.ID,'fastpostmessage').send_keys('不戳')
sleep(3)
    # 点击发表回复
dr.find_element(By.ID,'fastpostsubmit').click()
sleep(3)

# 退出
dr.find_element(By.LINK_TEXT,'退出').click()
sleep(3)
dr.quit()